package files;

import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;

/**
 * @Description
 * @Author zhaobaolin
 * @Date 2018/11/13
 */
public class FileExample {
    public static void main(String[] args) {
        demo();
    }
    private static void demo()
    {
        File file = new File("./io/src/files/1.txt");
        System.out.println("名称:"+file.getName());
        System.out.println("路径名称:"+file.getPath());
        System.out.println("绝对路径名称:"+file.getAbsolutePath());
        System.out.println("父目录的路径名称:"+file.getParent());
        System.out.println("是否存在:"+file.exists());
        System.out.println("是否可写:"+file.canWrite());
        System.out.println("是否可读:"+file.canRead());
        System.out.println("是否隐藏:"+file.isHidden());
        System.out.println("是否是目录:"+file.isDirectory());
        System.out.println("是否是文件:"+file.isFile());
        System.out.println("是否是绝对路径:"+file.isAbsolute());
        System.out.println("最后一次修改时间:"+file.lastModified());
        System.out.println("文件大小:"+file.length()+"bytes");

        System.out.println("--------------------");

        File file1 = new File(file.getParent());
        String[] s = file1.list();
        for(String str : s){
            System.out.println(str);
        }

        System.out.println("--------------------");

        FilenameFilter filenameFilter = new OnlyExt("txt");
        String[] strs = file1.list(filenameFilter);
        for(String t : strs){
            System.out.println(t);
        }

        System.out.println("--------------------");

        FileFilter fileFilter = new FilterExt("txt");
        File[] files = file1.listFiles(fileFilter);
        for(File f :files){
            System.out.println(f.getName());
        }
    }
}
